#pragma once
#include "const.h"

struct SectionInfo  {
    SectionInfo() {}

    std::map<std::string, std::string> _section_datas;

    ~SectionInfo() {
        _section_datas.clear();
    }

    SectionInfo(const SectionInfo& src) {
        _section_datas = src._section_datas;
    }
    SectionInfo& operator = (const SectionInfo& src) {
        if (&src == this) {
            return *this;
        }
        this->_section_datas = src._section_datas;
        return *this;
    }
    std::string GetValue(const std::string& key) {
        if (_section_datas.find(key) == _section_datas.end()) {
            return "";
        }
        return _section_datas[key];
    }
    std::string  operator[](const std::string& key) {
        if (_section_datas.find(key) == _section_datas.end()) {
            return "";
        }
        return _section_datas[key];
    }

};
class ConfigMgr
{

public:
    ~ConfigMgr();
    SectionInfo  operator[](const std::string& section) {
        if (_config_map.find(section) == _config_map.end()) {
            return SectionInfo();
        }
        return _config_map[section];
    }
    ConfigMgr& operator=(const ConfigMgr& mgr) {
        if (this == &mgr) {
            return *this;
        }
        this->_config_map = mgr._config_map;
        return *this;

    }
    ConfigMgr(const ConfigMgr& mgr) {
        this->_config_map = mgr._config_map;
    }
    static ConfigMgr& Inst() {
        static ConfigMgr cfg_mgr;
        return cfg_mgr;
    }
    std::string GetValue(const std::string& section, const std::string& key);
private:
   std::map<std::string, SectionInfo>_config_map;
   ConfigMgr();
   
};

